package cn.whit.blog.servlet;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.whit.blog.domain.Statistical;
import cn.whit.blog.domain.StatisticalType;
import cn.whit.blog.domain.User;
import cn.whit.blog.service.StatisticalService;
import cn.whit.blog.util.BeanFactory;
import net.sf.json.JSONArray;

public class StatisticalServlet extends BaseServlet{
	private static final long serialVersionUID = 1585543258583846725L;

	StatisticalService statisticalService = (StatisticalService) BeanFactory.createObject("statisticalService");
	
	
	public String getAllNameByBlogIdAndType(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		StatisticalType statisticalType = StatisticalType.valueOf(request.getParameter("type"));
		
		User loginUser = (User) request.getSession().getAttribute("loginUser");
		//转json字符串数组返回客户端
		List<Statistical> ones = statisticalService.findAllByTblogIdAndType(id, statisticalType);
		
		JSONArray jsonStr = JSONArray.fromObject(ones);
		response.setCharacterEncoding("utf-8");
		PrintWriter writer = response.getWriter();
		
		writer.write(jsonStr.toString());
		return null;
	}
}
